#include "Engine.hpp"
#include <iostream>

using namespace red;

int main(){
	try{
		Device device;
		device.Init();

		SceneManager& scene = device.GetSceneManager();

		Camera* c1 = scene.AddCamera();
		c1->LookAt(Vector3F(0,0,0), Vector3F(3,3,3));
		
		Text* t1 = scene.AddText("", Vector2I(10,22), Color::White, 12);
		t1->Enable(false);

		Texture t;
		t.LoadFromFile("crate.jpg");

		Shader s;
		s.Compile("baseShader.vs", "baseShader.fs");
		s.Bind();
		s.SendColor("color", Color(0.f, 0.8f, 0.8f));
		s.UnBind();
		scene.s1 = s;

		Vector3F vertices[3] = { Vector3F(-1,-1,0), Vector3F(1,-1,0), Vector3F(0,0,0) };
		Vector2F texcoords[3] = { Vector2F(0,1), Vector2F(1,1), Vector2F(0.5,0.5) };
		Index indices[3] = { 0, 1, 2 };

		VAO v1;
		v1.Begin(3);
		v1.AddBuffer(s, "position", vertices, sizeof(vertices));
		v1.AddBuffer(s, "texcoords", texcoords, sizeof(texcoords));
		v1.AddBuffer(indices, sizeof(indices));
		v1.End();

		scene.AddVAO(&v1);

		while(device.Run()){
			device.BeginRender();
				t.Bind();
				scene.RenderAll();
				t.UnBind();
			device.EndRender();
		}

	}catch(Exception e){
		OmniLog << e.what() << eol;
		system("PAUSE");
	}
	return 0;
}